# -*- coding: utf-8 -*-
import re
import pdb
def is_pku(school):
	return school == u'北京大学'
def is_matching_main_page(url):
	return re.compile(r'http://www\.renren\.com/[\d]+/profile$').match(url)
def is_matching_recent_view(url):
	return re.compile(r'http://www\.renren\.com/profile\.do\?portal=homeFootprint&').match(url)

def strip(str):
	return str.strip('\n')

def addline(str):
	return str + '\n'

class fileQueue:
        def __init__(self):
                self.file_name = 'fileQueue.txt'
                self.hash_name = 'fileHash.txt'
                self.file = open(self.file_name, 'r+')
                self.hash = open(self.hash_name, 'r+')

        def __del__(self):
                self.file.close()
                self.hash.close()

        def get_all(self):
                return map(strip, self.file.readlines())

        def push(self, uid):
                self.file.seek(0)
                self.hash.seek(0)
                queue = map(strip, self.file.readlines())
                res = map(strip, self.hash.readlines())
                res += queue
                for vid in res:
                        if (uid == vid):
                                return False
                self.file.write(uid + '\n');
		return True

        def pop(self, uid):
                self.file.seek(0)
                self.hash.seek(0)
                queue = []
                for vid in map(strip, self.file.readlines()):
                        if (uid != vid):
                                queue.append(vid)
                self.file.close()
                self.file = open(self.file_name, 'w')
                self.file.writelines(map(addline, queue))
                self.file.close()
                self.file = open(self.file_name, 'r+')
                self.file.seek(0)
                self.hash.readlines()
                self.hash.write(uid + '\n')

